<?php
class DealsDSBase extends AbstractDSBase {
	/**	 * The DealsEntity Object will be created before calling create function	 *	 * @access public	 *	 * @return DealsEntity object	 *	 */
	public function beforeCreate() {
		// New DealsEntity		$dealsEntity = new DealsEntity ();
		$dealsEntity = parent::beforeInsert ( $dealsEntity );
		
		// Return DealsEntity		return $dealsEntity;
	}
	
	/**	 * The DealsEntity Object will be getted item from database before calling update function	 *	 * @access public	 *	 * @param int $id: Id of the page	 *	 * @return DealsEntity object	 *	 */
	public function beforeUpdate($id) {
		// Get page item		$dealsEntity = $this->getById ( $id );
		
		// Return DealsEntity		return $dealsEntity;
	}
	
	/**	 * Insert new row to service	 *	 * @access public	 *	 * @param DealsEntity $dealsEntity: object to be inserted	 *	 * @return array of primary key of new inserted row	 */
	public function create($dealsEntity) {
		// New Data Access of service		$dealsDataAccess = new DealsDataAccess ();
		
		// Create service and return		return $dealsDataAccess->create ( $dealsEntity );
	}
	
	/**	 * Update an existing row of deals	 *	 * @access public	 *	 * @param DealsEntity $dealsEntity: object to be updated	 *	 * @return bool	 */
	public function update($dealsEntity) {
		// New Data Access of deals		$dealsDataAccess = new DealsDataAccess ();
		
		// Update service item and return		return $dealsDataAccess->update ( $dealsEntity );
	}
	
	/**	 * Delete an existing row of deals	 *	 * @access public	 *	 * @param int $id: id of row need to be deleted	 *	 * @return bool	 */
	public function del($id) {
		// New Data Access of deals		$dealsDataAccess = new DealsDataAccess ();
		$result = false;
		if (! is_null ( $id )) {
			
			// Detele deals and return			$result = $dealsDataAccess->del ( $id );
		}
		
		return $result;
	}
	
	/**	 * Get deals item	 *	 * @access public	 *	 * @param int $id: Id of deals	 *	 * @return DealsEntity object	 */
	public function getById($id) {
		// New Data Access of deals		$dealsDataAccess = new DealsDataAccess ();
		
		// Get deals item and return		return $dealsDataAccess->getById ( $id );
	}
	
	/**	 * Get all rows of deals table with search criterias	 *	 * @access public	 *	 * @param array $arrElement: array of search criterias	 * @param string $orderby: Field and the way ordered (ASC or DESC)	 * @param int $begin: Begin item	 * @param int $limit: Number rows to query	 * @param string $where: added where string	 * @param string $having: 	 * 	 * @return array DealsEntity object	 */
	public function getItems($arrElement, $orderby = null, $begin = null, $limit = null, $where = null, $having = null) {
		// New Data Access of service		$dealsDataAccess = new DealsDataAccess ();
		
		// Get all deals based on search criterias		return $dealsDataAccess->getItems ( $arrElement, $orderby, $begin, $limit, $where, $having );
	}
	
	public function getItemsAll($arrElement, $orderby = null, $begin = null, $limit = null, $where = null, $having = null) {
		// New Data Access of service		$dealsDataAccess = new DealsDataAccess ();
		
		// Get all deals based on search criterias		return $dealsDataAccess->getItemsAll ( $arrElement, $orderby, $begin, $limit, $where, $having );
	}
	
	public function getDealsOfGroupon($groupon_id = null) {
		// New Data Access of service		$dealsDataAccess = new DealsDataAccess ();
		
		// Get all deals based on search criterias		return $dealsDataAccess->getDealsOfGroupon ( $groupon_id );
	}
	
	public function getAllDealsOfCity($city) {
		// New Data Access of service		$dealsDataAccess = new DealsDataAccess ();
		
		return $dealsDataAccess->getAllDealsOfCity ( $city );
	}
	
	public function getAnotherDeals($dealId, $cityId) {
		// New Data Access of service		$dealsDataAccess = new DealsDataAccess ();
		
		return $dealsDataAccess->getAnotherDeals ( $dealId, $cityId );
	}
	/**	 * Get total items of deals	 *	 * @access public	 *	 * @param array $arrElement: array of search criterias	 *	 * @return int total: Num of rows of deals	 */
	public function getTotals($arrElement) {
		// New Data Access of deals		$dealsDataAccess = new DealsDataAccess ();
		
		// Get total items of deals based on search criterias and return		return $dealsDataAccess->getTotals ( $arrElement );
	}
	
	public function getAllDeals($arrElement, $orderby = null, $begin = null, $limit = null, $where = null, $having = null) {
		// New Data Access of service
		$dealsDataAccess = new DealsDataAccess ();
		
		// Get all deals based on search criterias
		return $dealsDataAccess->getAllDeals ( $arrElement, $orderby, $begin, $limit, $where, $having );
	}
	
}